
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><title>Python: module gummworld2.game_clock</title>
</head><body bgcolor="#f0f0f8">

<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="heading">
<tr bgcolor="#7799ee">
<td valign=bottom>&nbsp;<br>
<font color="#ffffff" face="helvetica, arial">&nbsp;<br><big><big><strong><a href="gummworld2.html"><font color="#ffffff">gummworld2</font></a>.game_clock</strong></big></big> (version $Id: game_clock.py 248 2011-02-25 15:40:01Z stabbingfinger@gmail.com $)</font></td
><td align=right valign=bottom
><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:///C:/cygwin/home/bw/devel/python/svn/gummworld2/gamelib/gummworld2/game_clock.py">c:\cygwin\home\bw\devel\python\svn\gummworld2\gamelib\gummworld2\game_clock.py</a></font></td></tr></table>
    <p><tt>#&nbsp;This&nbsp;file&nbsp;is&nbsp;part&nbsp;of&nbsp;Gummworld2.<br>
#<br>
#&nbsp;Gummworld2&nbsp;is&nbsp;free&nbsp;software:&nbsp;you&nbsp;can&nbsp;redistribute&nbsp;it&nbsp;and/or&nbsp;modify&nbsp;it<br>
#&nbsp;under&nbsp;the&nbsp;terms&nbsp;of&nbsp;the&nbsp;GNU&nbsp;Lesser&nbsp;General&nbsp;Public&nbsp;License&nbsp;as&nbsp;published<br>
#&nbsp;by&nbsp;the&nbsp;Free&nbsp;Software&nbsp;Foundation,&nbsp;either&nbsp;version&nbsp;3&nbsp;of&nbsp;the&nbsp;License,&nbsp;or<br>
#&nbsp;(at&nbsp;your&nbsp;option)&nbsp;any&nbsp;later&nbsp;version.<br>
#<br>
#&nbsp;Gummworld2&nbsp;is&nbsp;distributed&nbsp;in&nbsp;the&nbsp;hope&nbsp;that&nbsp;it&nbsp;will&nbsp;be&nbsp;useful,<br>
#&nbsp;but&nbsp;WITHOUT&nbsp;ANY&nbsp;WARRANTY;&nbsp;without&nbsp;even&nbsp;the&nbsp;implied&nbsp;warranty&nbsp;of<br>
#&nbsp;MERCHANTABILITY&nbsp;or&nbsp;FITNESS&nbsp;FOR&nbsp;A&nbsp;PARTICULAR&nbsp;PURPOSE.&nbsp;&nbsp;See&nbsp;the<br>
#&nbsp;GNU&nbsp;Lesser&nbsp;General&nbsp;Public&nbsp;License&nbsp;for&nbsp;more&nbsp;details.<br>
#<br>
#&nbsp;You&nbsp;should&nbsp;have&nbsp;received&nbsp;a&nbsp;copy&nbsp;of&nbsp;the&nbsp;GNU&nbsp;Lesser&nbsp;General&nbsp;Public<br>
#&nbsp;License&nbsp;along&nbsp;with&nbsp;Gummworld2.&nbsp;&nbsp;If&nbsp;not,&nbsp;see&nbsp;&lt;<a href="http://www.gnu.org/licenses/">http://www.gnu.org/licenses/</a>&gt;.</tt></p>
<p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#aa55cc">
<td colspan=3 valign=bottom>&nbsp;<br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Modules</strong></big></font></td></tr>
    
<tr><td bgcolor="#aa55cc"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
<td width="100%"><table width="100%" summary="list"><tr><td width="25%" valign=top><a href="time.html">time</a><br>
</td><td width="25%" valign=top></td><td width="25%" valign=top></td><td width="25%" valign=top></td></tr></table></td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ee77aa">
<td colspan=3 valign=bottom>&nbsp;<br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Classes</strong></big></font></td></tr>
    
<tr><td bgcolor="#ee77aa"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
<td width="100%"><dl>
<dt><font face="helvetica, arial"><a href="__builtin__.html#object">__builtin__.object</a>
</font></dt><dd>
<dl>
<dt><font face="helvetica, arial"><a href="gummworld2.game_clock.html#GameClock">GameClock</a>
</font></dt></dl>
</dd>
</dl>
 <p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ffc8d8">
<td colspan=3 valign=bottom>&nbsp;<br>
<font color="#000000" face="helvetica, arial"><a name="GameClock">class <strong>GameClock</strong></a>(<a href="__builtin__.html#object">__builtin__.object</a>)</font></td></tr>
    
<tr bgcolor="#ffc8d8"><td rowspan=2><tt>&nbsp;&nbsp;&nbsp;</tt></td>
<td colspan=2><tt>Run&nbsp;game&nbsp;engine&nbsp;at&nbsp;a&nbsp;constant&nbsp;game&nbsp;speed&nbsp;independent&nbsp;of&nbsp;variable&nbsp;FPS.<br>
Parameters:<br>
&nbsp;&nbsp;&nbsp;&nbsp;ticks_per_second&nbsp;-&gt;&nbsp;Positive&nbsp;integer.&nbsp;Constant&nbsp;ticks&nbsp;per&nbsp;second&nbsp;for<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;game&nbsp;physics.<br>
&nbsp;&nbsp;&nbsp;&nbsp;max_fps&nbsp;-&gt;&nbsp;Positive&nbsp;integer.&nbsp;Max&nbsp;frames&nbsp;allowed&nbsp;per&nbsp;second.&nbsp;A&nbsp;value&nbsp;of<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;zero&nbsp;allows&nbsp;unlimited&nbsp;frames.<br>
&nbsp;&nbsp;&nbsp;&nbsp;use_wait&nbsp;-&gt;&nbsp;Boolean.&nbsp;When&nbsp;True,&nbsp;<a href="#GameClock">GameClock</a>.<a href="#GameClock-tick">tick</a>()&nbsp;uses&nbsp;time.sleep&nbsp;to<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;throttle&nbsp;frames&nbsp;per&nbsp;second.&nbsp;This&nbsp;uses&nbsp;less&nbsp;CPU&nbsp;at&nbsp;the&nbsp;postential<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cost&nbsp;of&nbsp;smoothness.&nbsp;When&nbsp;False,&nbsp;<a href="#GameClock">GameClock</a>.<a href="#GameClock-tick">tick</a>()&nbsp;returns&nbsp;without<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;injecting&nbsp;any&nbsp;waits,&nbsp;and&nbsp;can&nbsp;result&nbsp;in&nbsp;smoother&nbsp;frames.<br>
&nbsp;&nbsp;&nbsp;&nbsp;max_frame_skip&nbsp;-&gt;&nbsp;Positive&nbsp;integer.&nbsp;Max&nbsp;game&nbsp;ticks&nbsp;allowed&nbsp;before<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;forcing&nbsp;a&nbsp;frame&nbsp;display.<br>
Properties:<br>
&nbsp;&nbsp;&nbsp;&nbsp;ticks_per_second&nbsp;-&gt;&nbsp;Read-write.&nbsp;See&nbsp;parameter&nbsp;ticks_per_second.<br>
&nbsp;&nbsp;&nbsp;&nbsp;max_fps&nbsp;-&gt;&nbsp;Read-write.&nbsp;See&nbsp;parameter&nbsp;max_fps.<br>
&nbsp;&nbsp;&nbsp;&nbsp;use_wait&nbsp;-&gt;&nbsp;Read-write.&nbsp;See&nbsp;parameter&nbsp;use_wait.<br>
&nbsp;&nbsp;&nbsp;&nbsp;max_frame_skip&nbsp;-&gt;&nbsp;Read-write.&nbsp;See&nbsp;parameter&nbsp;max_frame_skip.<br>
Methods:<br>
&nbsp;&nbsp;&nbsp;&nbsp;<a href="#GameClock-tick">tick</a>()&nbsp;-&gt;&nbsp;Game&nbsp;loop&nbsp;timer.&nbsp;Call&nbsp;once&nbsp;per&nbsp;game&nbsp;loop.<br>
&nbsp;&nbsp;&nbsp;&nbsp;<a href="#GameClock-get_time">get_time</a>()&nbsp;-&gt;&nbsp;Return&nbsp;the&nbsp;milliseconds&nbsp;elapsed&nbsp;in&nbsp;the&nbsp;previous&nbsp;call&nbsp;to&nbsp;<a href="#GameClock-tick">tick</a>().<br>
&nbsp;&nbsp;&nbsp;&nbsp;<a href="#GameClock-get_fps">get_fps</a>()&nbsp;-&gt;&nbsp;Return&nbsp;the&nbsp;frame&nbsp;rate&nbsp;from&nbsp;the&nbsp;previous&nbsp;second.<br>
&nbsp;&nbsp;&nbsp;&nbsp;<a href="#GameClock-get_ups">get_ups</a>()&nbsp;-&gt;&nbsp;Return&nbsp;the&nbsp;update&nbsp;rate&nbsp;from&nbsp;the&nbsp;previous&nbsp;second.<br>
&nbsp;&nbsp;&nbsp;&nbsp;<a href="#GameClock-interpolate">interpolate</a>()&nbsp;-&gt;&nbsp;Return&nbsp;float&nbsp;(range&nbsp;0&nbsp;to&nbsp;1)&nbsp;as&nbsp;prediction&nbsp;factor.<br>
&nbsp;&nbsp;&nbsp;&nbsp;<a href="#GameClock-update_ready">update_ready</a>()&nbsp;-&gt;&nbsp;Return&nbsp;boolean&nbsp;indicating&nbsp;if&nbsp;game&nbsp;should&nbsp;be&nbsp;updated.<br>
&nbsp;&nbsp;&nbsp;&nbsp;<a href="#GameClock-frame_ready">frame_ready</a>()&nbsp;-&gt;&nbsp;Return&nbsp;boolean&nbsp;indicating&nbsp;if&nbsp;display&nbsp;should&nbsp;be&nbsp;updated.<br>
&nbsp;&nbsp;&nbsp;&nbsp;<a href="#GameClock-reset">reset</a>()&nbsp;-&gt;&nbsp;Reset&nbsp;clock&nbsp;counters.<br>&nbsp;</tt></td></tr>
<tr><td>&nbsp;</td>
<td width="100%">Methods defined here:<br>
<dl><dt><a name="GameClock-__init__"><strong>__init__</strong></a>(self, ticks_per_second<font color="#909090">=25</font>, max_fps<font color="#909090">=0</font>, use_wait<font color="#909090">=True</font>, max_frame_skip<font color="#909090">=5</font>)</dt></dl>

<dl><dt><a name="GameClock-frame_ready"><strong>frame_ready</strong></a>(self)</dt><dd><tt>Call&nbsp;once&nbsp;per&nbsp;game&nbsp;loop.&nbsp;If&nbsp;True&nbsp;is&nbsp;returned,&nbsp;display&nbsp;a&nbsp;graphics&nbsp;frame.</tt></dd></dl>

<dl><dt><a name="GameClock-get_fps"><strong>get_fps</strong></a>(self)</dt><dd><tt>Return&nbsp;frames&nbsp;per&nbsp;second&nbsp;during&nbsp;the&nbsp;previous&nbsp;second.</tt></dd></dl>

<dl><dt><a name="GameClock-get_time"><strong>get_time</strong></a>(self)</dt><dd><tt>Return&nbsp;the&nbsp;milliseconds&nbsp;elapsed&nbsp;in&nbsp;the&nbsp;previous&nbsp;call&nbsp;to&nbsp;<a href="#GameClock-tick">tick</a>().</tt></dd></dl>

<dl><dt><a name="GameClock-get_ups"><strong>get_ups</strong></a>(self)</dt><dd><tt>Return&nbsp;updates&nbsp;per&nbsp;second&nbsp;during&nbsp;the&nbsp;previous&nbsp;second.</tt></dd></dl>

<dl><dt><a name="GameClock-interpolate"><strong>interpolate</strong></a>(self)</dt><dd><tt>Return&nbsp;a&nbsp;float&nbsp;representing&nbsp;the&nbsp;current&nbsp;position&nbsp;in&nbsp;between&nbsp;the<br>
previous&nbsp;gametick&nbsp;and&nbsp;the&nbsp;next&nbsp;one.&nbsp;This&nbsp;allows&nbsp;the&nbsp;main&nbsp;game&nbsp;loop&nbsp;to<br>
make&nbsp;predictive&nbsp;calculations&nbsp;between&nbsp;gameticks.</tt></dd></dl>

<dl><dt><a name="GameClock-reset"><strong>reset</strong></a>(self)</dt><dd><tt>Reset&nbsp;clock&nbsp;counters.</tt></dd></dl>

<dl><dt><a name="GameClock-tick"><strong>tick</strong></a>(self)</dt><dd><tt>Game&nbsp;loop&nbsp;timer.&nbsp;Call&nbsp;once&nbsp;per&nbsp;game&nbsp;loop&nbsp;to&nbsp;calculate&nbsp;runtime&nbsp;values.<br>
After&nbsp;calling,&nbsp;check&nbsp;the&nbsp;<a href="#GameClock-update_ready">update_ready</a>()&nbsp;and&nbsp;<a href="#GameClock-frame_ready">frame_ready</a>()&nbsp;methods.<br>
Sleep&nbsp;cycles&nbsp;are&nbsp;injected&nbsp;if&nbsp;use_wait=True.&nbsp;Returns&nbsp;the&nbsp;number&nbsp;of<br>
milliseconds&nbsp;that&nbsp;have&nbsp;elapsed&nbsp;since&nbsp;the&nbsp;last&nbsp;call&nbsp;to&nbsp;<a href="#GameClock-tick">tick</a>().</tt></dd></dl>

<dl><dt><a name="GameClock-update_ready"><strong>update_ready</strong></a>(self)</dt><dd><tt>Call&nbsp;once&nbsp;per&nbsp;game&nbsp;loop.&nbsp;If&nbsp;True&nbsp;is&nbsp;returned,&nbsp;update&nbsp;the&nbsp;game&nbsp;physics.</tt></dd></dl>

<hr>
Data descriptors defined here:<br>
<dl><dt><strong>__dict__</strong></dt>
<dd><tt>dictionary&nbsp;for&nbsp;instance&nbsp;variables&nbsp;(if&nbsp;defined)</tt></dd>
</dl>
<dl><dt><strong>__weakref__</strong></dt>
<dd><tt>list&nbsp;of&nbsp;weak&nbsp;references&nbsp;to&nbsp;the&nbsp;object&nbsp;(if&nbsp;defined)</tt></dd>
</dl>
<dl><dt><strong>max_fps</strong></dt>
<dd><tt>Get&nbsp;or&nbsp;set&nbsp;max_fps.</tt></dd>
</dl>
<dl><dt><strong>max_frame_skip</strong></dt>
<dd><tt>Get&nbsp;or&nbsp;set&nbsp;max_frame_skip.</tt></dd>
</dl>
<dl><dt><strong>ticks_per_second</strong></dt>
<dd><tt>Get&nbsp;or&nbsp;set&nbsp;ticks&nbsp;per&nbsp;second.</tt></dd>
</dl>
<dl><dt><strong>use_wait</strong></dt>
<dd><tt>Get&nbsp;or&nbsp;set&nbsp;use_wait.</tt></dd>
</dl>
</td></tr></table></td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#55aa55">
<td colspan=3 valign=bottom>&nbsp;<br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Data</strong></big></font></td></tr>
    
<tr><td bgcolor="#55aa55"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
<td width="100%"><strong>__author__</strong> = 'Gummbum, (c) 2011'<br>
<strong>__version__</strong> = '$Id: game_clock.py 248 2011-02-25 15:40:01Z stabbingfinger@gmail.com $'</td></tr></table><p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#7799ee">
<td colspan=3 valign=bottom>&nbsp;<br>
<font color="#ffffff" face="helvetica, arial"><big><strong>Author</strong></big></font></td></tr>
    
<tr><td bgcolor="#7799ee"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
<td width="100%">Gummbum,&nbsp;(c)&nbsp;2011</td></tr></table>
</body></html>